package org.wei.p2p.account.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.wei.p2p.account.service.IAccountService;
import org.wei.p2p.api.account.AccountApi;
import org.wei.p2p.api.account.model.AccountDTO;
import org.wei.p2p.api.account.model.AccountLoginDTO;
import org.wei.p2p.api.account.model.AccountRegisterDTO;
import org.wei.p2p.api.account.model.VerificationInfoDTO;

import javax.annotation.Resource;

/**
 * @author wei
 * @date 2022/4/21 14:41
 */
@Slf4j
@RestController
@Tag(name = "ACCOUNT",description = "统一账号服务")
public class AccountController implements AccountApi {

    @Resource
    private IAccountService accountService;

    @Override
    @Operation(description = "获取短信验证码")
    @GetMapping("/sms/{mobile}")
    public VerificationInfoDTO getSMSCode(@PathVariable String mobile) {
        return accountService.getSMSCode(mobile);
    }

    @Override
    @Operation(description = "校验手机号和验证码")
    @GetMapping(value = "/mobiles/{mobile}/key/{key}/code/{code}")
    public Integer checkMobile(@PathVariable String mobile,
                               @PathVariable String key,
                               @PathVariable String code) {

        return accountService.checkMobile(mobile, key, code);
    }

    @Override
    @Operation(description = "用户注册")
    @PostMapping("/l/accounts")
    public AccountDTO register(@RequestBody AccountRegisterDTO accountRegisterDTO) {
        return accountService.register(accountRegisterDTO);
    }

    @Override
    public AccountDTO login(AccountLoginDTO accountLoginDTO) {
        return null;
    }
}
